package cn.byapps.hw.dao;

import cn.byapps.hw.entity.Clazz;
import cn.byapps.hw.entity.Course;
import cn.byapps.hw.entity.SerialPK;
import cn.byapps.hw.entity.Teacher;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface SerialPKDao extends JpaRepository<SerialPK, Integer> {
    /**
     * 根据老师实体获取
     *
     * @param teacher 老师实体
     * @return
     */
    @Query("select (u) from SerialPK u where u.teacher = :teacher")
    List<SerialPK> getClazzByTeacher(Teacher teacher);

    /**
     * 根据班级实体获取
     *
     * @param clazz 班级实体
     * @return
     */
    @Query("select (u) from SerialPK u where u.clazz = :clazz")
    List<SerialPK> getClazzByTeacherNums(Clazz clazz);

    /**
     * 根据课程实体获取
     *
     * @param course 课程实体
     * @return
     */
    @Query("select (u) from SerialPK u where u.course = :course")
    List<SerialPK> getCourse(Course course);

    /**
     * @param course
     * @param teacher
     * @param clazz
     * @return
     */
    @Query("select (u) from SerialPK u where u.course = :course and u.teacher = :teacher and u.clazz = :clazz")
    SerialPK getByTeacherAndCourse(Course course, Teacher teacher, Clazz clazz);

    @Query("select (u) from SerialPK u where u.course.id = :courseId and u.clazz.id = :clazzId")
    SerialPK getByClazzAndCourse(Integer courseId, Integer clazzId);
}
